package com.example.administrator.kotlintutorial.extenction

import java.io.File

/**
 * Created by chensuilun on 2019/2/21.
 */

// 扩展函数实际上是生成了一个工具类，并且是静态解析，不具多态性
//
//public final class FuncExtenctionKt {
//@Nullable
//public static final String getExt(@NotNull File $receiver) {
//    String absolutePath = $receiver.getAbsolutePath();
//    int index = StringsKt__StringsKt.lastIndexOf$default((CharSequence) absolutePath, ".", 0, false, 6, null);
//    if (index <= -1) {
//        return null;
//    }
//    String absolutePath2 = $receiver.getAbsolutePath();
//    int i = index + 1;
//    if (absolutePath2 != null) {
//        absolutePath2 = absolutePath2.substring(i);
//        return absolutePath2;
//    }
//    throw new TypeCastException("null cannot be cast to non-null type java.lang.String");
//}
//}

fun File.getExt(): String? {
    val index = absolutePath.lastIndexOf(".")
    if (index > -1) {
        return absolutePath.substring(index + 1)
    }
    return null
}